package com.sxg.controller;

import com.sxg.query.SxgGoodsInfoQuery;
import com.sxg.utils.code.AjaxResult;
import com.sxg.vo.SxgGoodsInfoVO;
import com.sxg.vo.resp.GoodsDetailsRespVo;
import lombok.AllArgsConstructor;
import com.sxg.utils.code.Result;
import com.sxg.service.SxgGoodsInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 商品信息
*
* @author 浪漫写尽歌谱 3298751420@qq.com
* @since 1.0.0 2024-03-07
*/
@RestController
@RequestMapping("sxg/sxg_goods_info")
@AllArgsConstructor
public class SxgGoodsInfoController {
    private final SxgGoodsInfoService sxgGoodsInfoService;

    @GetMapping("page")
    public AjaxResult page(@Valid SxgGoodsInfoQuery query){
        return sxgGoodsInfoService.page(query);
    }

    @GetMapping("{id}")
    public Result<GoodsDetailsRespVo> get(@PathVariable("id") Long id){
        return Result.ok(sxgGoodsInfoService.selectDetailById(id));
    }

    @PostMapping
    @PreAuthorize("hasAuthority('sxg:sxg_goods_info:save')")
    public Result<String> save(@RequestBody SxgGoodsInfoVO vo){
        sxgGoodsInfoService.save(vo);
        return Result.ok();
    }

    @PutMapping
    @PreAuthorize("hasAuthority('sxg:sxg_goods_info:update')")
    public Result<String> update(@RequestBody @Valid SxgGoodsInfoVO vo){
        sxgGoodsInfoService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @PreAuthorize("hasAuthority('sxg:sxg_goods_info:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        sxgGoodsInfoService.delete(idList);

        return Result.ok();
    }
}